window.addEvent('domready',function(){
	$('approveView').slide('out');
	$('rejectView').slide('out');
	
	//approve
	new FormCheck($('approveView').getElement('form'),{submitByAjax:true, 
        onAjaxSuccess: function(res){
			var json = JSON.decode(res);
			if (json.error)	FBModal_message(APP.base+'/ajax/messageDialog', "Save", json.msg);
			else location.replace(json.url);
        }
    });
	
	//BAP
	$$('.RTE').mooEditable({
		actions: "bold italic underline strikethrough | formatBlock justifyleft justifyright justifycenter justifyfull | " +
				"insertunorderedlist insertorderedlist indent outdent | undo redo | createlink unlink | " +
				"urlimage | toggleview",
		dimensions:{x:'100%', y:'300px'}
	});
	
	$('tpl_saksi3').addEvent('click',function(){
		search_saksi(this);
	});
	
	//reject
	new FormCheck($('rejectView').getElement('form'),{submitByAjax:true, 
        onAjaxSuccess: function(res){
			var json = JSON.decode(res);
			if (json.error)	FBModal_message(APP.base+'/ajax/messageDialog', "Save", json.msg);
			else location.replace(json.url);
        }
    });
});

function showImage(title, imageTitle, imageUrl){
	FBModal_show2(APP.utils+'/imageViewer', 'post', 
		"title="+title+
		"&imageTitle="+imageTitle+
		"&imageUrl="+imageUrl+
		"&maxWidth="+(screen.width-50)+
		"&maxHeight="+(screen.height-50), true, false, null, {
		onSuccess: function(res){}
		});
}

function doNone(){
	$('approveView').slide('out');
	$('rejectView').slide('out');
	$('detailView').getElement("input[type='button']").getParent('div').slide('in');
}

function doApprove(){
	$('approveView').slide('in');
	$('rejectView').slide('out');
	$('detailView').getElement("input[type='button']").getParent('div').slide('out');
}

function doReject(){
	$('approveView').slide('out');
	$('rejectView').slide('in');
	$('detailView').getElement("input[type='button']").getParent('div').slide('out');
}

function moreSaksi(button){
	var ind = $chk(APP.saksiCount)? APP.saksiCount : 1;
	ind++;
	APP.saksiCount = ind;
	var inp1 = $('tpl_saksi1').clone(true).set('name', 'inp[AP][saksi]['+ind+'][1]').set('value','');
	var inp2 = $('tpl_saksi2').clone(true).set('name', 'inp[AP][saksi]['+ind+'][0]').set('value','');
	var inp3 = $('tpl_saksi3').clone(true).setStyle('margin-left','8px');
	inp3.cloneEvents($('tpl_saksi3'));
	var aa = new Element('a',{html:'delete'}).addEvent('click',function(){
		APP.saksiCount--;
		this.getParent('tr').destroy();
	}).setStyle('margin-left','8px');
	var td = new Element('td').grab(inp1).grab(inp2).grab(inp3).grab(aa);
	new Element('tr').grab(new Element('td')).grab(td).inject($(button).getParent('tr'),'before');
	
	$('approveView').slide('in');
}

function search_saksi(button){
	APP.saksiSearchButton = button;

	var exclude = "";
	$$('input[name^="inp[AP][saksi]"]').each(function(item){
		if (item.type=="hidden") exclude+= (exclude? ",":"")+"'"+item.value+"'";
	});
	
	FBModal_show2(APP.utils +'/searchDialog/karyawan/getDialog', 'post', 
		"submit_action=search_saksi2"+
		"&where=kary_id NOT IN("+APP.saksiSearchWhere+") AND kary_id NOT IN ("+exclude+")", true, false, null, {
		onSuccess: function(res){
			Utils.searchDialog.install({
				form:'karyawanSearchFrm',
				pagination:'karyawanSearchFrm_pagination',
				table: {
					element:'karyawanSearchFrm_table',
					columns:['kary_id','kary_nama','kary_status_marital','kary_email','kary_tgl_masuk'],
					content:'karyawanSearchFrm_tableContent',
				}
			});
		}
	});
}

function search_saksi2(id, nama){
	var tr = APP.saksiSearchButton.getParent('tr');
	var el = tr.getElements('input');
	el[0].value = nama;
	el[1].value = id;
	FBModal_hide();
}